#!/bin/sh
. /etc/utils.sh

if is-html-tv-ui; then
  echo "configured for chrome"
  exit 0
elif ! is-tv-box; then
  echo "miniclient only runs on tv box"
  exit 0
fi

case "$1" in
  start)
    (
      wait-until-created /tmp/nexus_multiprocess
      rc_pipe_init
      setuid appclient:video /app/client/runminiclient 2>&1 | logos miniclient 0 20000000 &
    ) &
    ;;
  stop)
    pkillwait -x startupvideo  # if it's running, prevents miniclient from starting up
    pkillwait -x runminiclient
    pkillwait -x miniclient
    pkillwait -x waitpower
    pkillwait -x netflix
    pkillwait -x browser_shell
    pkillwait -x fiber_shell
    pkillwait -x vudu
    pkillwait -x StandaloneWFDPlayer
    rc_pipe_deinit
    ;;
  restart)
    $0 stop; $0 start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
esac
